package edu.mercer.medapps.documentbldr;

import static com.google.common.base.Preconditions.checkNotNull;


/**
 * DocumentBuilder provides chained method calls for creation of Document 
 * instances.<p>
 * 
 * @see DocumentCreation
 */

class DocumentBuilder implements DocumentCreation<DocumentBuilder,
												  DocumentProperties,
												  ValidFile>
{		
	private final DocumentProperties _docProp = new DocumentProperties();

	
	DocumentBuilder()
	{
		super();
		
		_docProp.clear();
				
	}//constructor
	
	
	@Fulfills("Document")
	public DocumentProperties properties()
	{ 
		return _docProp; 
		
	}//method
	
	
	@Fulfills("DocumentCreation")
	public DocumentBuilder fromFile( final ValidFile fileNameIn )
	{
		return this.fromFile( fileNameIn.toString() );
		
	}//method


	@Fulfills("DocumentCreation")
	public DocumentBuilder fromFile( final String fileNameIn )
	{
		_docProp.replace("filename",fileNameIn);

		return this;
		
	}//method

	
	@Fulfills("DocumentCreation")
	public DocumentBuilder name(final String nameIn)
	{
		checkNotNull(nameIn, "null detected name in argument");
		
		_docProp.replace("name",nameIn);
		
		return this;
		
	}//method
	

	/**
	 * Supply this DocumentBuilder instance with the properties object set to 
	 * Document implementation.<p>
	 * 
	 * @return Document - with properties copied from this (Builder instance)
	 */
	
	@Fulfills("DocumentCreation")
	public Document<DocumentProperties> build()
	{
		return new DocumentDemo(this);
		
	}//method


}//class
